﻿using MediatR;
using Tb.App.API.Applications.Command.Cultivation;
using Tb.App.Domain.Rabbit.Cultivation;
using Tb.App.ErrorCode;
using Tb.App.Infrastructure.Interfaces;

namespace Tb.App.API.Applications.CommandHandler.Cultivation
{
    /// <summary>
    /// 养殖信息查询-命令
    /// </summary>
    public class GetCultivationQueryCommandHandler : IRequestHandler<GetCultivationQueryCommand, ApiResult<CultivationModel>>
    {
        private readonly IBaseRepository<CultivationModel> culRep;

        public GetCultivationQueryCommandHandler(IBaseRepository<CultivationModel> culRep)
        {
            this.culRep = culRep;
        }
        public Task<ApiResult<CultivationModel>> Handle(GetCultivationQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<CultivationModel> result = new ApiResult<CultivationModel>();
            result.Code=ApiEnum.查询成功;
            result.Message = ApiEnum.查询成功.ToString();

            var list=culRep.GetAll().Where(x=>!x.IsDel&&x.Batch==request.Batch).OrderByDescending(x=>x.Id).FirstOrDefault();
            result.Data = list;

            return Task.FromResult(result);

        }
    }
}
